package com.naiterui.ehp.bs.emr.entity.mongo;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.data.annotation.Transient;

/**
 * 可选择类档案：过敏药物、既往病史、遗传病、酒类
 *

 * @since 2.16
 */
public class MSelectOrOthers implements Serializable {

    /**
     * 字段或域定义：<code>serialVersionUID</code>
     */
    private static final long serialVersionUID = 1584713552684851190L;
    /**
     * <状态：0无；1有>
     */
    private Short status;
    /**
     * <选中疾病，逗号分隔>
     */
    private String defaultSelect = "";
    /**
     * <其他（手动输入）>
     */
    private String others = "";

    @Transient
    private String defaultNames = "";

    public String getDefaultNames() {
        if (StringUtils.isEmpty(this.defaultSelect) && StringUtils.isEmpty(this.others)) {
            return "";
        } else if (StringUtils.isEmpty(this.defaultSelect)) {
            this.defaultNames = this.others;
        } else if (StringUtils.isEmpty(this.others)) {
            this.defaultNames = this.defaultSelect;
        } else {
            this.defaultNames = this.defaultSelect + "," + this.others;
        }
        return this.defaultNames;
    }

    public void setDefaultNames(String defaultNames) {
        this.defaultNames = defaultNames;
    }

    public String describe() {
        Short status = this.getStatus();
        if (status == null) {
            return null;
        }
        if (status == 1) {
            return this.getDefaultNames();

        } else if (status == 0) {
            return "无";
        }
        return null;
    }

    public Short getStatus() {
        return this.status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public String getDefaultSelect() {
        return this.defaultSelect;
    }

    public void setDefaultSelect(String defaultSelect) {
        this.defaultSelect = defaultSelect;
    }

    public String getOthers() {
        if (StringUtils.isNotEmpty(this.defaultSelect) && StringUtils.isNotEmpty(this.others) && this.defaultSelect.contains(this.others)) {//
            // 选择默认项与输入其它冲突，过滤其它
            this.others = "";
        }
        return this.others;
    }

    public void setOthers(String others) {
        this.others = others;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
